package com.example.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sys.entity.Menu;
import com.example.sys.mapper.MenuMapper;
import com.example.sys.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sys.vo.MenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单权限表 服务实现类
 * </p>
 *
 * @author anan
 * @since 2019-06-20
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> findMenuByUserId(Long userId) {
        return menuMapper.findMenuByUserId(userId);
    }

    @Override
    public IPage<Menu> selectPage(MenuVo menuVo) {
        IPage<Menu> iPage = new Page<>(menuVo.getPage(),menuVo.getLimit());
        QueryWrapper<Menu> wrapper = new QueryWrapper<>();
        if (menuVo.getParentId()>=0)
            wrapper.eq("parent_id", menuVo.getParentId());
        if (!StrUtil.hasEmpty(menuVo.getMenuName()))
            wrapper.like("menu_name", menuVo.getMenuName());
        if (!StrUtil.hasEmpty(menuVo.getVisible()))
            wrapper.eq("visible", menuVo.getVisible());
        return menuMapper.selectPage(iPage, wrapper);
    }

    @Override
    public List<Menu> selectRoleKey() {
        return menuMapper.selectRoleKey();
    }
}
